package org.vectrics.recruiter.user.resume.email;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import org.vectrics.SystemException;

public class WordList extends ArrayList {

	public WordList() {
		super();
	}

	public Word findWord(int index) {
		Word found = null;
		if (index < this.size())
			found = (Word)this.get(index);
		return(found);
	}
	
	public boolean add(Object object) {
		if (object.getClass().equals(Word.class)) {
			return super.add(object);
		} else {
			throw new SystemException("Attempt to add an object that is not of class Word, class = " + object.getClass().getName());
		}
	}
	
	/**
	 * Determine if a particular phrase exists in the word list.
	 * @param wordText
	 * @return True if the phrase is in this list.
	 */
	public boolean hasWord(String phrase) {
		Word word = this.findWord(phrase);
		return(word != null);
	}

	/**
	 * Find the first occurance of a phrase in the word list.
	 * @param phrase
	 * @return
	 */
	public Word findWord(String phrase) {
		Word found = null;
		Iterator iter = this.iterator();
		while (iter.hasNext()) {
			Word word = (Word)iter.next();
			if (word.getValue().equals(phrase)) {
				found = word;
			}
		}
		return(found);
	}

	
	
	public String toString() {
		String wordStr = "WordList:\r\n";
		Iterator wordIter = this.iterator();
		while (wordIter.hasNext()) {
			Word word = (Word)wordIter.next();
			wordStr += "[" + word + "]\r\n";
		}
		return(wordStr);
	}
	
}
